package com.xzbd.gef.cmd;


import java.util.Objects;

import org.eclipse.gef.commands.Command;

import com.xzbd.gef.model.connection.AbstractConnectionModel;
import com.xzbd.gef.model.connection.ConnectionPort;

public class DeleteConnectionCommand extends Command {
	private AbstractConnectionModel model;
	private ConnectionPort source;
	private ConnectionPort target;

	public void setModel(AbstractConnectionModel model) {
		this.model = model;
		this.source = model.getSrc();
		this.target = model.getTarget();
	}

	public void execute() {
		if(Objects.isNull(source) || Objects.isNull(target)){
			return;
		}
		model.deattachSource();
		model.deattachTarget();
	}

	public void undo(){
		if(Objects.isNull(source) || Objects.isNull(target)){
			return;
		}
		model.attachSource();
		model.attachTarget();
	}

}
